package com.leetcode;

/**
 * 把二叉搜索树转换为累加树
 *
 * @author winson
 * @create 2022-04-20 10:47
 */
public class ConvertBSTSolution {

    int sum = 0;

    public TreeNode convertBST(TreeNode root) {
        if (root != null) {
            /**
             * 节点不为空，先求右节点、根节点、左节点
             */
            convertBST(root.right);
            sum += root.val;
            root.val = sum;
            convertBST(root.left);
        }
        return root;
    }
}
